﻿//
// Created by Administrator on 2022/10/24.
// 荷兰国旗, 分成小于等于区和大于区
//
#include <iostream>

using namespace std;

void swap(int &a, int &b)
{
    int t = a;
    a = b;
    b = t;
}

void printArr(int *arrP, int n)
{
    for (int i = 0; i < n; ++i) printf("%d ", *arrP++);
    printf("\n");
}

int le(int *a, int len)
{
    int le = -1;
    int value = *a;
    for (int i = 0; i < len; ++i)
    {
        if (value<a[i])
        {
            le++;
            swap(a[le],a[i]);
        }
    }
    return le;
}


int main()
{

    int arr[] = {2, 8, 7, 6, 9, 4, 3, 2, 1, 0};
    int len = 10;
    le(arr,len);
    printArr(arr,len);
 /*
    int le = -1;     // less equal area
    int value = arr[0];
    for (int i = 0; i < len; ++i)
    {
        if (arr[i] < value)
        {
            le++;
            swap(arr[le], arr[i]);
        }
    }
    printArr(arr, len);

  */
}

